/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controler.formbeans;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/**
 *
 * @author Maha
 */
public class ContactUsMsgBean extends org.apache.struts.action.ActionForm {

    private String senderName;
    private String phone;
    private String email;
    private String subject;
    private String msg;
    private String confirm;

    public ContactUsMsgBean() {
        super();

    }

    public String getSenderName() {
        return senderName;
    }

    public void setSenderName(String senderName) {
        this.senderName = senderName;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getConfirm() {
        return confirm;
    }

    public void setConfirm(String confirm) {
        this.confirm = confirm;
    }

    @Override
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();
        if (getSenderName() == null || getSenderName().length() < 1) {
            errors.add("name", new ActionMessage("errors.contactname"));
            // TODO: add 'error.name.required' key to your resources
        }
        if (getPhone() == null || getPhone().length() < 7) {
            errors.add("phone", new ActionMessage("errors.contactphone"));
        }
        if (getEmail() == null) {
            errors.add("emptymail", new ActionMessage("errors.emptymail"));
        }
        if (!getEmail().matches("^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+$")) {
            errors.add("unmatch", new ActionMessage("errors.unmatchedmail"));
        }
        if (getSubject() == null || getSubject().length() < 3) {
            errors.add("subject", new ActionMessage("errors.subject"));
        }
        if (getMsg() == null || getMsg().length() < 1) {
            errors.add("msg", new ActionMessage("errors.msg"));
        }

        return errors;
    }
}
